home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Frameworks / Extension Shell 1.3 / Sample Extensions / CircleMouse ][ ƒ / CircleMouse ][.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-06  |  6.9 KB  |  274 lines  |  [TEXT/R*ch]

  1. /*    NAME:
  2.         CircleMouse ][.c
  3.  
  4.     WRITTEN BY:
  5.         Dair Grant
  6.                 
  7.     DESCRIPTION:
  8.         This file contains a CODE resource to be used as a handler by
  9.         Extension Shell.
  10.  
  11.     ___________________________________________________________________________
  12.  
  13.     VERSION HISTORY:
  14.         (Jan 1994, dg)
  15.             •    First publicly distributed version.
  16.  
  17.  
  18.     ___________________________________________________________________________
  19. */
  20. //=============================================================================
  21. //        Include files                                                                     
  22. //-----------------------------------------------------------------------------
  23. #include <Retrace.h>
  24. #include "CircleMouse ][.h"
  25. #include "ParamBlock.h"
  26. #include "StandaloneCode.h"
  27. #include "ESConstants.h"
  28. #include "CodeConstants.h"
  29.  
  30.  
  31.  
  32.  
  33.  
  34. //=============================================================================
  35. //        Private function prototypes                                                                     
  36. //-----------------------------------------------------------------------------
  37. void    main(short theMsg, ESParamBlock *theParamBlock);
  38. void    InitialiseParamBlock(void);
  39. void    InitialiseAddrsTable(void);
  40. void    HandleTheError(void);
  41. void    SetUpIcons(int animDelay, int numIcons, int firstIcon);
  42.  
  43.  
  44.  
  45.  
  46.  
  47. //=============================================================================
  48. //        Global variables                                                                 
  49. //-----------------------------------------------------------------------------
  50. ESParamBlock    *gTheParamBlock;
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61. //=============================================================================
  62. //        main : Entry point to our code resource.                                                                 
  63. //-----------------------------------------------------------------------------
  64. //        Note :    Extension Shell communicates with us via a message constant,
  65. //                and a pointer to a structure it owns. Our job is to fill in
  66. //                the details, depending on what it wants us to do. It takes
  67. //                care of the rest.
  68. //-----------------------------------------------------------------------------
  69. void main(short theMsg, ESParamBlock *theParamBlock)
  70. {
  71.  
  72.  
  73.  
  74.  
  75.     // Set up A4 so that we can access our globals, and initialise them.
  76.     GetGlobals();
  77.     gTheParamBlock = theParamBlock;
  78.  
  79.  
  80.  
  81.     // Case out on what we have to do
  82.     switch(theMsg) {
  83.         case kInitialiseParamBlock:
  84.              InitialiseParamBlock();
  85.              break;
  86.              
  87.         case kInitialiseAddrsTable:
  88.              InitialiseAddrsTable();
  89.              break;
  90.  
  91.         case kHandleError:
  92.              HandleTheError();
  93.              break;
  94.     
  95.         default:
  96.              ;
  97.     }
  98.  
  99.  
  100.  
  101.     // Restore A4.
  102.     UngetGlobals();
  103. }
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114. //=============================================================================
  115. //        InitialiseParamBlock : Initialises the ParamBlock.                                                                 
  116. //-----------------------------------------------------------------------------
  117. //        Note :    We have three things we want to do:
  118. //                    • Check to see if we can still run
  119. //                    • Set up the icons we want to display
  120. //                    • Set up the code we want installed
  121. //-----------------------------------------------------------------------------
  122. void InitialiseParamBlock(void)
  123. {    int        i;
  124.  
  125.  
  126.  
  127.  
  128.     // Check for System 7. We depend on having System 7, and won't
  129.     // run if we don't have it. We beep, post an error message,
  130.     // and show our disabled icon(s).
  131.     if (gTheParamBlock->systemVersion < 0x0700)
  132.         {
  133.         // Error details
  134.         gTheParamBlock->beepNow                = true;
  135.         gTheParamBlock->postError            = true;
  136.         gTheParamBlock->errorStringsID        = kErrorStrings;
  137.         gTheParamBlock->errorStringIndex    = kNeedSystemSeven;
  138.  
  139.  
  140.         // Icon details
  141.         SetUpIcons(kDisabledAnimDelay, kMyNumDisabledIcons, kMyFirstDisabledIcon);
  142.         }
  143.     
  144.     
  145.     
  146.     // If a shift key, or the mouse button, is down, we don't load either.
  147.     // We don't post an error, but we do show our disabled icon(s).
  148.     else if ((*gTheParamBlock->UserForcedDisable)(kShiftKey, true))
  149.         {
  150.         // Icon details
  151.         SetUpIcons(kDisabledAnimDelay, kMyNumDisabledIcons, kMyFirstDisabledIcon);
  152.         }
  153.     
  154.     
  155.     
  156.     // Otherwise, we're allowed to run so we show our icon(s) as normal,
  157.     // and fill in the details for the code we want installed.
  158.     else
  159.         {
  160.         // Icon details
  161.         SetUpIcons(kEnabledAnimDelay, kMyNumEnabledIcons, kMyFirstEnabledIcon);
  162.         
  163.         
  164.         // We install one VBL task, with no address table.
  165.         gTheParamBlock->installAddressTable                = false;
  166.         gTheParamBlock->numCodeResources                = 1;
  167.  
  168.  
  169.         // Details for a VBL task
  170.         gTheParamBlock->theCodeResources[kCircleVBL].resType    = kCircleVBLResType;
  171.         gTheParamBlock->theCodeResources[kCircleVBL].resID        = kCircleVBLResID;
  172.         gTheParamBlock->theCodeResources[kCircleVBL].codeType    = kVBLTaskType;
  173.         gTheParamBlock->theCodeResources[kCircleVBL].theCodeThing.theVBLTask.vblCount = 1000;
  174.         gTheParamBlock->theCodeResources[kCircleVBL].theCodeThing.theVBLTask.vblPhase = 0;
  175.         }
  176. }
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187. //=============================================================================
  188. //        InitialiseAddrsTable : Initialise the address table.                                                     
  189. //-----------------------------------------------------------------------------
  190. //        Note :    If we are being used in a Control Panel, we will probably have
  191. //                implemented the address table code with a custom code resource
  192. //                that returns a structure with an address table embedded at the
  193. //                start. This function's job is to correctly initialise the
  194. //                extended fields of that structure. If we're not using a
  195. //                (custom) address table then we don't do anything.
  196. //
  197. //                The message for this routine will only arrive if we've
  198. //                requested an address table.
  199. //-----------------------------------------------------------------------------
  200. void InitialiseAddrsTable(void)
  201. {
  202.  
  203.  
  204.  
  205. }
  206.  
  207.  
  208.  
  209.  
  210.  
  211.  
  212.  
  213.  
  214.  
  215.  
  216. //=============================================================================
  217. //        HandleTheError : Handle any errors                                                             
  218. //-----------------------------------------------------------------------------
  219. //        Note :    If any error occurs, we beep, post an error, and remove our
  220. //                code. We also have to reset the icon details to show our
  221. //                disabled icons.
  222. //-----------------------------------------------------------------------------
  223. void HandleTheError(void)
  224. {
  225.  
  226.  
  227.  
  228.  
  229.     // General error handling settings
  230.     gTheParamBlock->removeInstalledCode    = true;
  231.     gTheParamBlock->beepNow                = true;
  232.     gTheParamBlock->postError            = true;
  233.     gTheParamBlock->errorStringsID        = kErrorStrings;
  234.  
  235.  
  236.  
  237.     // Icon details
  238.     SetUpIcons(kDisabledAnimDelay, kMyNumDisabledIcons, kMyFirstDisabledIcon);
  239.  
  240.  
  241.  
  242.     // Just give a general error.
  243.     gTheParamBlock->errorStringIndex = kUnknownError;
  244. }
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255. //=============================================================================
  256. //        SetUpIcons : Set up our icons accordingly.                                                         
  257. //-----------------------------------------------------------------------------
  258. //        Note :    We are passed in the resource ID of the first icon, the number
  259. //                of icons, and a delay for animation. We just fill in the fields
  260. //                in the paramBlock.
  261. //-----------------------------------------------------------------------------
  262. void SetUpIcons(int animDelay, int numIcons, int firstIcon)
  263. {    int        i;
  264.  
  265.  
  266.  
  267.  
  268.     // Fill in the fields
  269.     gTheParamBlock->animationDelay    = animDelay;
  270.     gTheParamBlock->numIcons        = numIcons;
  271.     for (i = 1; i <= numIcons; i++)
  272.         gTheParamBlock->theIcons[i] = firstIcon + i - 1;
  273. }
  274.